// 药房管理
<template comments>
  <div class="pharmacy">
    <TopManu :signOut="true" @handleQuit="$router.go(-1)"></TopManu>
    <div class="box">
      <div class="boxLeft">
     
        <el-tree
          :data="subjectData"
          :props="defaultProps"
          @node-click="handleNodeClick"
        ></el-tree>
      </div>
      <div>
        <div class="search">
             <div class="s1">
                <el-input
                v-model="params.keyword"
                placeholder="请输入名称"
                ></el-input>
            
                <el-button @click="searchB()">查询</el-button>
                  <el-button @click="add()">新增</el-button>
            </div>
        </div>

        <div class="tablesB">
          <el-table v-loading="params.loading" :data="data" border>
            <el-table-column type="index" width="70" label="序号">
            </el-table-column>
            <template
              v-for="(item, index) in $baseBai['doctorScheduling']['list']"
            > 

              
         
                 <el-table-column :width="item.width" v-if="item.prop == 'week'" :prop="item.prop" :label="item.label" :key="index">
                        <template slot-scope="scope">
                                <span v-if="scope.row.one==1">星期一、</span>
                                <span v-if="scope.row.two==1">星期二、</span>
                                <span v-if="scope.row.three==1">星期三、</span>
                                <span v-if="scope.row.four==1">星期四、</span>
                                <span v-if="scope.row.five==1">星期五、</span>
                                <span v-if="scope.row.six==1">星期六、</span>
                                <span v-if="scope.row.seven==1">星期日</span>
                            
                        </template>
              </el-table-column>
              
          
              <el-table-column
              v-else
                :width="item.width"
                :prop="item.prop"
                :label="item.label"
                :key="index + item"
              >
              </el-table-column>
            </template>
               <el-table-column label="操作" width="250" fixed="right">
          <template slot-scope="scope">
            <div>
              <el-button
                size="mini"
                type="danger"
                @click="handleEdit(scope.$index, scope.row, 1)"
                >编辑</el-button
              >
               <el-button
                size="mini"
                type="danger"
                @click="handleEdit(scope.$index, scope.row, 2)"
                >删除</el-button
              >
            </div>
             
          </template>
        </el-table-column>
          </el-table>
          <div>
            <el-pagination
              class="fenye"
              :background="true"
              :current-page="params.page"
              :page-size="params.limit"
              layout="prev, pager, next"
              @current-change="handlePagination"
              :total="params.pageCount"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>

       <el-dialog
      :title="dialogTitle"
      :visible.sync="Detail_Show"
      :destroy-on-close="true"
      v-if="Detail_Show"
      :close-on-click-modal="false"
      width="30%"
      :before-close="
        () => {
          this.Detail_Show = !this.Detail_Show;
        }
      "
    >
      <Save :dialogTitle="dialogTitle" :that="this"></Save>
    </el-dialog>
  </div>
</template>

<script>
let t;

import TopManu from "@/components/TopMenu";
import Save from './common/save'
import { mapState, mapActions } from "vuex";
// getDict_dataKuFangList
export default {
  data() {
    return {
      Detail_Show: false,
     value1:'',
    dialogTitle:'',
      params: {
        loading: false,
       
        page: 1,
        limit: 10,
        keyword:'',
        pageCount: 0,
      },
    
      data: [],
      subjectData: [],
      defaultProps: {
        children: "children",
        label: "name",
      },

      paramsSave:{},
    };
  },
  
  components: {
    TopManu,
     Save,
  },

  mounted() {
    t = this;

   
    t.deptDepartment();
  },
  
  methods: {
    getregister_confWorkScheduleSet(){

           this["_API"].getregister_confFeeSave(d).then((res) => {
        if (res.code == 200) {
          t.Detail_Show = !t.Detail_Show;
          t.params.page = 1;
          t.getList();
        }
      });
    },
    add(){
        t.dialogTitle='排班新增'
          t.paramsSave = {
              id:'',
              start_time:'',
              end_time:'',
              week:[],
              user_id:'',
              real_name:'',
            };
          
         t.Detail_Show = !t.Detail_Show;
    },
    addSave(){

        if(!t.paramsSave.user_id){
          return t.$message.error('请选择医生')
        }
         if(!t.paramsSave.start_time){
          return t.$message.error('请选择出诊开始时间')
        }
         if(!t.paramsSave.end_time){
          return t.$message.error('请选择出诊结束时间')
        }
          let d={
            user_id:t.paramsSave.user_id,
            start_time:t.paramsSave.start_time?t.paramsSave.start_time.replace('-',':'):'',
            end_time:t.paramsSave.end_time?t.paramsSave.end_time.replace('-',':'):'',
            one: t.paramsSave.week.findIndex(v=>v==1)>-1?1:2,
            two: t.paramsSave.week.findIndex(v=>v==2)>-1?1:2,
            three: t.paramsSave.week.findIndex(v=>v==3)>-1?1:2,
            four: t.paramsSave.week.findIndex(v=>v==4)>-1?1:2,
            five: t.paramsSave.week.findIndex(v=>v==5)>-1?1:2,
            six: t.paramsSave.week.findIndex(v=>v==6)>-1?1:2,
            seven: t.paramsSave.week.findIndex(v=>v==7)>-1?1:2,
          }

          if (t.paramsSave.id) {
            d.id =t.paramsSave.id ;
            
          } 


          t['_API'].getregister_confWorkScheduleSet(d).then(res=>{
             if (res.code == 200) {
              t.Detail_Show = !t.Detail_Show;
              t.params.page = 1;
              t.getList();
            }
          })
    },
    handleEdit(...item){
      console.log("item",item)
      let week=[];
      if(item[1].one==1){
        week.push(1);
      }
      if(item[1].two==1){
        week.push(2);
      }
       if(item[1].three==1){
        week.push(3);
      }
       if(item[1].four==1){
        week.push(4);
      }
       if(item[1].five==1){
        week.push(5);
      }
      if(item[1].six==1){
        week.push(6);
      }
      if(item[1].seven==1){
        week.push(7);
      }


      if(item[2]==1){
            t.dialogTitle='排班编辑'
            t.paramsSave = {
              id: item[1].id,
              start_time:item[1].start_time?item[1].start_time.replace(':','-'):'',
              end_time:item[1].end_time?item[1].end_time.replace(':','-'):'',
              week:week,
              user_id:item[1].doctor.id,
              real_name:item[1].doctor.real_name,
            };
          
         t.Detail_Show = !t.Detail_Show;
      }else{
        let d={
          id:item[1].id
        }
           t['_API'].getregister_confFeeWorkScheduleDel(d).then(res=>{
            if(res.code==200){
               this.$message({
                message: res.message,
                type: 'success'
              });
              t.getList()
            }
        })
      }
    },
   handleNodeClick(...item){
   
     
       t.getList(item[0].id)
   },
     onchangeSwitch(...item){
       console.log("item",item)
        let d={
          user_id:item[0].user_id,
          one:item[0].one?1:2,
          two:item[0].two?1:2,
          three:item[0].three?1:2,
          four:item[0].four?1:2,
          five:item[0].five?1:2,
          six:item[0].six?1:2,
          seven:item[0].seven?1:2,
          
        }
        if(item[0].time){
            d.start_time=item[0].time[0]?item[0].time[0].replace('-',':'):'';
            d.end_time=item[0].time[1]?item[0].time[1].replace('-',':'):'';
        }else{
            d.start_time='';
            d.end_time='';
        }
        t['_API'].getregister_confFeeWorkScheduleSet(d).then(res=>{
            if(res.code==200){
               this.$message({
                message: res.message,
                type: 'success'
              });
            }
        })
     },
    deptDepartment() {
      this["_API"].getdeptIndex({}).then((res) => {
        if (res.code == 200) {
          this.subjectData = res.data;
          t.getList(this.subjectData[0].id)
        }
      });
    },
    
    

    searchB() {
      t.params.page = 1;
      t.getList();
    },
  onchangeTime(...item){
    
    console.log("item",item)
  },
    handlePagination(e) {
      t.params.page = e;
      t.getList();
    },
    getList(dept_id) {
      let d = {
        keyword:t.params.keyword,
        page:t.params.page,
        limit:t.params.limit,
      };
      if(dept_id){
        d.dept_id=dept_id;
      }
      
      
      t.data = [];
      this.params.loading = true;
     
      this["_API"].getregister_confFeeWorkScheduleGet(d).then((res) => {
        this.params.loading = false;
        if (res.code == 200) {
          this.data = res.data.list.map(v=>{
              return {
                ...v,
                // one:v.one==1?true:false,
                // two:v.two==1?true:false,
                // three:v.three==1?true:false,
                // four:v.four==1?true:false,
                // five:v.five==1?true:false,
                // six:v.six==1?true:false,
                // seven:v.seven==1?true:false,
                // time:[v.start_time?v.start_time.replace(':','-'):'',v.end_time?v.end_time.replace(':','-'):''],
              }

          });
          this.params.pageCount = res.data.count;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/ .el-tabs__nav {
  .el-tabs__item {
    border-bottom: 1px solid #e4e7ed;
  }
  .is-active {
    color: #02bf6b;
  }
  .el-tabs__item:hover {
    color: #02bf6b;
  }
}
.search {
  border: 1px solid #f2f2f2;
  margin: 10px 2%;
  padding: 20px;
  border-radius: 10px;
  .s1 {
    width: 400px;
    display: flex;
    .el-input {
      margin-right: 10px;
    }
    button {
      margin-left: 20px;
      margin-bottom: 20px;
      background-color: #02bf6b;
      color: white;
    }
  }
  .selectBai {
    display: flex;
    > div {
      margin-right: 10px;
    }
  }
}

.tableMore {
  /deep/ .el-button--primary {
    color: black;
    background-color: initial;
    border-color: #e2e2e2;
  }
}
.tablesB,
.tabsB {
  margin: 20px 2% 0;
}

.fenye {
  text-align: right;
  margin-top: 20px;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #02bf6b;
}

/deep/ .el-dialog {
  width: 500px !important;
}
.box {
  display: flex;
  .boxLeft{
        background: #f3f3f3;
  }
  > :nth-child(1) {
    // padding-left: 40px;
    padding-top: 2px;
    width: 400px;
    height: 80vh;
    border-right: 25px solid #f7f7f7;
  }
  > :nth-child(2) {
      flex: 1;
  }
  .title {
    background-color: #02bf6b;
    color: white;
    height: 50px;
    line-height: 50px;
    font-size: 18px;
  }
}

/deep/ .el-tree-node__content {
  padding: 20px;
  line-height: 50px;
  height: 50px;
}

/deep/ .el-tree-node__label{
  font-size: 18px;
}
</style>